<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <style>
        .active { 
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="box">
        <ul>
            <!-- 意思为触发点击事件后，进行判断，不成立为空字符串，成立则赋值给class -->
            <li v-for="(item, index) in datalist" :class="current === index? 
            'active': '' " @click="handleClick(index)">
                {{item}}
            </li>
        </ul>
    </div>
    
    <script>
        new Vue ({
            el: '#box',
            data: {
                datalist: ['首页', '列表', '购物车'],
                current: 0
            },
            methods: {
                handleClick (index) {
                    this.current = index
                }
            }
        })
    </script>
</body>
</html>